﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using EvoWars2.Stuffs;
using EvoWars2.Stuffs.TankStuff;

namespace EvoWars.Stuffs.TankStuff
{
    public class Tank : CollisionObject
    {
        public bool IsHumanControlled { get; set; }
        public string Name { get; set; }
        public int Id { get; set; }


        public TankAttributes Attributes { get; set; }
        public decimal CurrentHealth { get; set; }
        public TimeSpan CurrentShotCooldown { get; private set; }
        public IArtificialIntelligence AI { get; set; }
        public TankSensor Sensor { get; set; }

        private Vector2 currentVelocity;
        public Vector2 CurrentVelocity
        {
            get { return currentVelocity; }
            set
            {
                currentVelocity = value;

                //dont change the heading after we stor moving,
                //just continue to point in the same direction
                //( LengthSquared() is faster than Length() )
                if (currentVelocity.LengthSquared() > 0)
                {
                    Heading = (float)Math.Atan2(CurrentVelocity.Y, CurrentVelocity.X) + MathHelper.PiOver2;
                }
            }
        }

        private float heading;
        public float Heading
        {
            get { return heading; }
            private set { heading = value; }
        }



        public Tank()
        {
            Attributes = new TankAttributes();
            SetBoundingBox(56, 57);
            CurrentShotCooldown = new TimeSpan(0, 0, 0);
        }


        private void SetBoundingBox(int width, int height)
        {
            int boxX = (int)(-(width / 2.0));
            int boxY = (int)(-(height / 2.0));
            BoundingBox = new Rectangle(boxX, boxY, width, height);

        }





        public void FireGun(Vector2 direction)
        {
            if (CurrentShotCooldown.TotalMilliseconds <= 0)
            {


            }
            else
            {
                //do nothing, still on cooldown
            }

        }


        public void DoAIUpdate(TimeSpan elapsedTime)
        {
            AI.DoUpdate(elapsedTime);
        }

        public void UpdateCooldown(TimeSpan elapsedTime)
        {
            CurrentShotCooldown = CurrentShotCooldown.Subtract(elapsedTime);
        }



    }
}
